#Loading Data
# loading spatial data
pacnty.load <- readOGR("./PA_Counties_clip/PA_Counties_clip.shp", layer = "PA_Counties_clip", GDAL1_integer64_policy = TRUE)
## OGR data source with driver: ESRI Shapefile
## Source: "C:\Users\BadMix\Desktop\CMU Classes\Fall 18\R Shiny\Homework\hw3-atolson\PA_Counties_clip\PA_Counties_clip.shp", layer: "PA_Counties_clip"
## with 67 features
## It has 13 fields
# loading economic data
econ.load <- read.csv("./aff_download/ACS_16_5YR_S1903_with_ann.csv")
# loading rail line data
rail <- readOGR("PaRailLines2018_07.geojson")
## OGR data source with driver: GeoJSON
## Source: "C:\Users\BadMix\Desktop\CMU Classes\Fall 18\R Shiny\Homework\hw3-atolson\PaRailLines2018_07.geojson", layer: "PaRailLines2018_07"
## with 893 features
## It has 34 fields
# loading school location data
school <- read_excel("Urban Centric and Metro Centric Locale Codes.xls")%>%
#fixing lat & lon so it comes up as numbers
mutate(Longitude = as.numeric(as.character(Longitude)), Latitude = as.numeric(as.character(Latitude)))
# merging spatial & econ data
pacnty <- pacnty.load[pacnty.load$NAME %in% econ.load$County,]
pacnty@data <- merge(pacnty@data, econ.load, sort = FALSE, by.x = "NAME", by.y = "County")
Economic Status in PA
#palette defined
pal <- colorNumeric(
palette = "Blues",
domain = pacnty$Median_Income)
#leaflet plot with PA median income colored
leaflet(data = pacnty) %>%
addProviderTiles("Esri.WorldTopoMap", options = providerTileOptions(noWrap = TRUE)) %>%
addPolygons(color = ~pal(`Median_Income`), popup = ~paste0("<b>", NAME, ":</b> $", format(Median_Income, big.mark = ","))) %>%
addLegend(position = "topright", pal = pal, values = pacnty$Median_Income, title = "Median Income by County (dollars)")
Rail Lines in PA
#leaflet plot with Rail Lines
leaflet(data = rail) %>%
addProviderTiles("Stamen.Toner", options = providerTileOptions(noWrap = TRUE)) %>%
addPolylines(color = "#a8ddb5")
Schools in PA
#leaflet plot with clustered school locations
leaflet(data = school) %>%
addProviderTiles("Stamen.Terrain") %>%
addCircleMarkers(lng = ~Longitude, lat = ~Latitude, radius = 1.5, clusterOptions = markerClusterOptions())